feat: add skills command to read embedded skill content#1277
feat: add skills command to read embedded skill content#1277dc-bytedance wants to merge 2 commits into
Conversation
|
Looking for one thing? Review this PR in Change Stack to search files, summaries, diffs, and code without losing your place. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an embedded skills filesystem, a skillcontent.Reader, Cobra ChangesSkills command
Sequence DiagramsequenceDiagram
participant User
participant SkillCmd as skills command
participant Reader as skillcontent.Reader
participant FS as embedded fs.FS
User->>SkillCmd: list [skill[/path]]
SkillCmd->>SkillCmd: validate args (≤1)
SkillCmd->>Reader: List() or ListPath()
Reader->>FS: readdir, open SKILL.md
FS-->>Reader: content, entries
Reader->>Reader: parse YAML frontmatter
Reader-->>SkillCmd: []SkillInfo or []DirEntry
SkillCmd->>SkillCmd: emit JSON envelope
SkillCmd-->>User: JSON or error
User->>SkillCmd: read name[/path] [path]
SkillCmd->>SkillCmd: parseReadTarget()
SkillCmd->>Reader: ReadSkill() or ReadReference()
Reader->>FS: stat, open file
FS-->>Reader: bytes
Reader-->>SkillCmd: content, cleanPath
SkillCmd->>SkillCmd: append guidance (SKILL.md only)
SkillCmd->>SkillCmd: JSON or raw markdown
SkillCmd-->>User: output or error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@51a72d000657818e82a61d20915cc9f17c3bc2f9🧩 Skill updatenpx skills add dc-bytedance/cli#feat/skill-content-read -y -g |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1277 +/- ##
==========================================
+ Coverage 70.93% 70.99% +0.06%
==========================================
Files 684 687 +3
Lines 65653 65878 +225
==========================================
+ Hits 46572 46773 +201
- Misses 15403 15417 +14
- Partials 3678 3688 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/skill/skill_test.go`:
- Around line 25-33: The run test helper does not isolate CLI config state, so
before calling cmdutil.TestFactory(t, ...) set the environment variable
LARKSUITE_CLI_CONFIG_DIR to a temp dir using
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()); update the run function
(around invocation of cmdutil.TestFactory and creation of NewCmdSkill) to call
t.Setenv(...) first to ensure each test gets an isolated config directory.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 699b2379-1c2e-460f-aae9-d334c1633dd0
📒 Files selected for processing (6)
cmd/build.gocmd/skill/skill.gocmd/skill/skill_test.gointernal/skillcontent/reader.gointernal/skillcontent/reader_test.goskills_embed.go
8d67578 to
b0ac518
Compare
b0ac518 to
bd4433f
Compare
Apply the PR larksuite#1277 review: - Inject the embedded skill tree via a BuildOption + Factory field instead of a package global set in init(): skills_embed.go exposes skillContentOptions() (degrades with a stderr warning, no panic), Execute takes variadic BuildOptions, WithSkillContent wires Factory.SkillContent, and cmd/skill reads it from the Factory. Removes the package global, init(), panic, and the t.Parallel ban in tests. - Surface the frontmatter version field in `skills list` for drift detection. - Scope the read guidance tip to the skill's own files and stop disparaging direct reads; emit it on stderr in raw mode (stdout stays byte-identical to SKILL.md) and in the --json guidance field. - Use typed structs for the list and read JSON envelopes. - Share one path splitter (skillcontent.SplitArg) between read and list. - Skip top-level directories without a SKILL.md in List(). - Add usage examples to `skills list` and `skills read`.
Add a top-level `lark-cli skills` meta command group that reads skill content compiled into the binary at build time via go:embed, so the content an AI agent reads always matches the running CLI version. It is an additional, version-consistent source and a fallback for when skills are not installed or are stale; it does not replace or thin the on-disk skills. Commands: - `skills list` lists every embedded skill with name, description, and the frontmatter metadata block. - `skills list <name>` / `skills list <name>/<sub>` list one directory layer (ls-style, no recursion); entries are skill-prefixed paths that can be fed straight back to `read`. - `skills read <name>` prints the skill's SKILL.md and appends a one-line tip steering the model to fetch reference files via this command. - `skills read <name> <path>` / `skills read <name>/<path>` print any file under the skill directory (no tip). - `--json` wraps output in an envelope; on the main SKILL.md it carries a separate `guidance` field instead of merging the tip into content. Implementation: - skills/ is embedded from the repo-root package main (go:embed cannot cross parent dirs) and injected into cmd/skill via a package variable, avoiding any change to cmd.Execute's signature. - internal/skillcontent is pure logic over an injected fs.FS; reference reads and directory listings share one path-traversal guard that rejects absolute paths, "..", and "..\\" escapes. - Errors are typed (validation -> exit 2, file_io -> exit 5); rejected paths never write anything to stdout. Risk is set per leaf subcommand (read); the group carries none, matching the config/service command groups. The commands need no auth (local embed reads only).
Apply the PR larksuite#1277 review: - Inject the embedded skill tree via a BuildOption + Factory field instead of a package global set in init(): skills_embed.go exposes skillContentOptions() (degrades with a stderr warning, no panic), Execute takes variadic BuildOptions, WithSkillContent wires Factory.SkillContent, and cmd/skill reads it from the Factory. Removes the package global, init(), panic, and the t.Parallel ban in tests. - Surface the frontmatter version field in `skills list` for drift detection. - Scope the read guidance tip to the skill's own files and stop disparaging direct reads; emit it on stderr in raw mode (stdout stays byte-identical to SKILL.md) and in the --json guidance field. - Use typed structs for the list and read JSON envelopes. - Share one path splitter (skillcontent.SplitArg) between read and list. - Skip top-level directories without a SKILL.md in List(). - Add usage examples to `skills list` and `skills read`.
14faa30 to
c6274f5
Compare
Squashes the review-response iteration on top of the initial skills command. - Inject the embedded tree via an init() calling cmd.SetEmbeddedSkillContent (no cmd/skill package global, no panic; tests inject through the Factory). main.go stays self-contained so the single-file preview build (go build ./main.go) still compiles. - Surface the frontmatter version field in `skills list`. - Use typed structs for the list and read JSON envelopes. - Scope the read guidance tip to the skill's own files, route cross-skill "../lark-foo/..." references back through `skills read`, and emit it on stderr in raw mode (stdout stays byte-identical to SKILL.md) and in a guidance field under --json. - Share one path splitter (skillcontent.SplitArg) between read and list. - Skip top-level directories without a SKILL.md in List(). - Add usage examples to `skills list` and `skills read`. - Isolate config state in the command test helper. - Slim the embed to agent-readable content (SKILL.md + references/, plus lark-whiteboard's routes/ and scenes/), excluding machine-resource assets/ and scripts/: release binary 26.7 -> 23.4 MB, no change to what the commands serve.
962e1ab to
51a72d0
Compare
Summary
lark-cli ships one skill per business domain, but skills install through a separate channel and carry their own version, so after a CLI upgrade an on-disk skill can fall out of sync with the binary (the docs v1/v2 drift is a concrete case). This PR adds a
lark-cli skillscommand group that reads skill content compiled into the binary at build time viago:embed, giving AI agents a version-consistent source — and a fallback for when skills are not installed or are stale. It does not replace or thin the on-disk skills.Changes
skills_embed.go(package main)://go:embed skillsplus aninit()thatfs.Sub-roots the tree and injects it intocmd/skillvia a package variable, avoiding any change tocmd.Execute's signature.internal/skillcontent/reader.go: pure logic over an injectedfs.FS—List(skills with name/description/frontmatter metadata),ListPath(one directory layer, ls-style, no recursion),ReadSkill,ReadReference, and a sharedcleanSubPathtraversal guard.cmd/skill/skill.go: theskillscommand group withlist(catalog, or one-layer listing of<name>/<name>/<sub>) andread(<name>,<name> <path>, or<name>/<path>); reading the main SKILL.md appends a one-line guidance tip (a separateguidancefield under--json).cmd/build.go.cmd/skill/skill_test.go,internal/skillcontent/reader_test.go).Test Plan
make unit-testpassedlark-cli skills list,skills list lark-doc,skills list lark-doc/references,skills read lark-calendar [--json],skills read lark-doc references/lark-doc-fetch.md,skills read lark-doc/references/lark-doc-fetch.md; error paths (read no-such-skill,read lark-calendar ../../etc/passwd,read,list a b) all exit 2 with empty stdoutRelated Issues
N/A
Summary by CodeRabbit
New Features
skills listandskills read(supports raw and--jsonmodes).Quality